
# Dockerfile for Laradock PHP-FPM 

ARG PHP_VERSION=8.2
ARG SITE_DIR=/var/www

FROM php:${PHP_VERSION}-fpm-alpine


#--------------------------------------------------------------------------
# Optional Software's Installation
#--------------------------------------------------------------------------

  
# ① 安装编译依赖 + linux-headers
ARG PHP_EXTENSIONS="pdo_mysql intl opcache sockets bcmath pcntl"
RUN set -eux \
    && apk add --no-cache \
         $PHPIZE_DEPS \
         icu-dev zlib-dev oniguruma-dev tzdata shadow \
         linux-headers \
    # ② 编译所需扩展
    && docker-php-ext-install $PHP_EXTENSIONS \
    # ③ 安装并启用 pecl 扩展
    && pecl install redis \
    && docker-php-ext-enable redis \
    # ④ 可选：精简镜像体积
    && apk del linux-headers $PHPIZE_DEPS

# 安装 Composer
RUN set -eux && \
    curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
    composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

# 更新php配置和fpm配置
COPY ./docker/php/php.ini /usr/local/etc/php/conf.d
COPY ./docker/php/www.conf /usr/local/etc/php-fpm.d/

# Configure non-root user.
ARG PUID=1000
ARG PGID=1000

RUN groupmod -o -g ${PGID} www-data && \
    usermod -o -u ${PUID} -g www-data www-data && \
    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

# 创建日志目录
RUN mkdir -p /var/log/php-fpm && \
    chown www-data:www-data /var/log/php-fpm && \
    chmod 755 /var/log/php-fpm
RUN mkdir -p /var/lib/php && \
    chown www-data:www-data /var/lib/php && \
    chmod 755 /var/lib/php

# 设置工作目录
WORKDIR ${SITE_DIR}
USER www-data

CMD ["php-fpm", "-F"]

EXPOSE 9000
